<template>
    <section>
        <!--列表-->
        <div class="panel">
            <div class="panel-head">
                <strong><span class="el-icon-date"/><span class="title">编辑个人信息</span></strong>
            </div>
            <div class="infor-div">
                <el-form label-width="120px">
                    <el-form-item label="登录名">
                        <el-col class="line" :span="2">{{userName}}</el-col>
                    </el-form-item>
                    <el-form-item label="密码">
                        <el-col class="line" :span="4">
                            <el-input type="password" v-model.trim="password" size="small" width="200"/>
                        </el-col>
                    </el-form-item>
                    <el-form-item label="真实姓名">
                        <el-col class="line" :span="2">{{name}}</el-col>
                    </el-form-item>
                    <el-form-item label="工作手机">
                        <el-col class="line" :span="2">{{mobile}}</el-col>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" size='small' @click="updatePassword">更新</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </section>
</template>

<script>
import { updatePwd, checkLogin } from "../../api/api";

export default {
    data() {
        return {
            mobile: "",
            loading: false,
            name: "",
            userName: "",
            password: "",
            adminId: ""
        };
    },
    methods: {
        //登录是否失效验证
        logincheck() {
            checkLogin().then(() => {});
        },
        // 更新用户密码
        updatePassword() {
            if (this.password == "") {
                this.$message.error("密码不能为空！");
                return;
            }
            //校验规则 正则表达式  只允许输入 数字跟字母
            var reg = /^[A-Za-z0-9]{6,10}$/;
            if (!reg.test(this.password)) {
                this.$message.error("密码为六到十位的数字和字母的组合！");
                return;
            }
            //修改密码 请求
            updatePwd({
                pwd: this.password
                // adminId: this.adminId
            })
                .then(() => {
                    this.$message({
                        type: "success",
                        message: "修改成功!"
                    });
                    this.$router.push("/login");
                })
                .catch(() => {
                    this.$message.error("网络挂啦，请求不到数据！");
                });
        }
    },
    mounted() {
        this.logincheck();
        var roleData = JSON.parse(sessionStorage.getItem("data"));
        this.name = roleData.adminUser.name;
        this.userName = roleData.adminUser.userName;
        this.mobile = roleData.adminUser.mobile;
        this.adminId = roleData.adminUser.autoId;
    }
};
</script>

<style scoped>
.infor-div {
    margin: 10px;
}
</style>
